<include file="Public:header" />
<script src="__PUBLIC__/js/PCASClass.js" type="text/javascript"></script>
<div class="container">
<!-- Docs nav ================================================== -->
<div class="page-header" style="border:none; font-size:14px; ">
    <ul class="nav nav-tabs">
        <li <if condition="$_GET['content'] == 'customer' || $_GET['content'] == ''">class="active"</if>><a  href="{:U('customer/index')}"><img src="__PUBLIC__/img/customer_icon.png"/>&nbsp; {:L('CUSTOMER')}</a></li>

        <li <if condition="$_GET['content'] == 'taste' "> class="active" </if>><a  href="{:U('taste/index','content=taste')}"><img src="__PUBLIC__/img/tongji.png"/>&nbsp; 试吃申请</a></li>

        <li <if condition="$_GET['content'] == 'resource' "> class="active" </if>><a  href="{:U('customer/index','content=resource')}"><img src="__PUBLIC__/img/customer_source_icon.png"/>&nbsp; 客户池</a></li>
        <li><a href="{:U('contacts/index')}"><img src="__PUBLIC__/img/contacts_icon.png"/> &nbsp;联系人</a></li>
        <li><a href="{:U('customer/cares')}"><img src="__PUBLIC__/img/cares_icon.png"/> &nbsp;客户关怀</a></li>
        <li><a href="{:U('customer/analytics')}"><img src="__PUBLIC__/img/tongji.png"/> &nbsp;客户统计</a></li>
    </ul>
</div>
<include file="Public:alert" />
<if condition="$_GET['content'] != 'resource'">
    <p class="view hide">
        <b>{:L('UNIFIED_CUSTOMER_VIEW')}</b>
        <img src=" __PUBLIC__/img/by_owner.png"/> <a href="{:U('customer/index')}" <if condition="$Think.get.by eq null">class="active"</if>>{:L('ALL')}</a> |
        <a href="{:U('customer/index','by=me')}" <if condition="$Think.get.by eq 'me'">class="active"</if>>{:L('MY_CLIENTS')}</a> |
        <a href="{:U('customer/index','by=sub')}" <if condition="$Think.get.by eq 'sub'">class="active"</if>>{:L('SUBORDINATES_TO_THE_CUSTOMER')}</a> &nbsp;  &nbsp;
        <img src="__PUBLIC__/img/by_time.png"/>
        <a href="{:U('customer/index','by=today')}" <if condition="$Think.get.by eq 'today'">class="active"</if>>{:L('TODAY_IS_NEW')}</a> |
        <a href="{:U('customer/index','by=week')}" <if condition="$Think.get.by eq 'week'">class="active"</if>>{:L('THIS_WEEK_THE_NEW')}</a> |
        <a href="{:U('customer/index','by=month')}" <if condition="$Think.get.by eq 'month'">class="active"</if>>{:L('THIS_MONTH_THE_NEW')}</a>&nbsp;|&nbsp;
        <a href="{:U('customer/index','by=focus')}" <if condition="$Think.get.by eq 'focus'">class="active"</if>>我关注的</a>&nbsp;|&nbsp;
        <a href="{:U('customer/index','by=myshare')}" <if condition="$Think.get.by eq 'myshare'">class="active"</if>>我共享的</a>&nbsp;|&nbsp;
        <a href="{:U('customer/index','by=share')}" <if condition="$Think.get.by eq 'share'">class="active"</if>>共享给我的</a>&nbsp;&nbsp;
        <a href="{:U('customer/index','by=deleted')}" <if condition="$Think.get.by eq 'deleted'">class="active"</if>><img src="__PUBLIC__/img/task_garbage.png"/> {:L('RECYCLE_BIN')}</a>
        &nbsp; <img src=" __PUBLIC__/img/seach.png"/><a href="{:U('customer/search')}">{:L('ADVANCED_SEARCH')}</a>
    </p>
</if>
<div class="row">

    <div class="span12">
        <ul class="nav pull-left">
        <volist name="list" id="taste">
            <li class="pull-left" customer-id="{$taste.customer_id}" taste-id="{$taste.id}">
            <table class="table" width="95%" border="0" cellspacing="1" cellpadding="0">
                <tbody>
                <tr>
                    <td class="tdleft">
                        试吃客户名称：
                    </td>
                    <td>
                        <a href="{:U('customer/view', 'id='.$taste['customer_id'])}">{$taste.name}</a>
                    </td>
                    <td class="tdleft">
                        试吃原因：
                    </td>
                    <td>
                        {$taste.reason}
                    </td>
                    <td class="tdleft">
                        试吃人数：
                    </td>
                    <td>
                        {$taste.taster_num}
                    </td>
                    <td class="tdleft">
                        试吃商品：
                    </td>
                    <td>
                        {$taste.product}
                    </td>
                    <td class="tdleft">
                        试吃收货地址：
                    </td>
                    <td>
                        {$taste.delivery_address}
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">物料需求：</td>
                    <td>
                        {$taste.materiel_support}
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">
                        收货人姓名：
                    </td>
                    <td>
                        {$taste.contact_name}
                    </td>
                    <td class="tdleft">
                        收货人联系电话：
                    </td>
                    <td>
                        {$taste.phone_number}
                    </td>
                    <td class="tdleft">
                        配送时间：
                    </td>
                    <td>
                        {$taste.delivery_time}
                    </td>
                    <td class="tdleft">
                        备注：
                    </td>
                    <td colspan="2">
                        {$taste.memo}
                    </td>
                    <td>
                        <span style="color: blue;">试吃状态：</span>
                        <if condition="$taste.status eq '0'">
                            总经理助理尚未审核
                        </if>
                        <if condition="$taste.status eq '4'">
                            已通过
                        </if>
                        <if condition="$taste.status eq '2'">
                            未通过
                        </if>
                    </td>
                </tr>
                </tbody>
            </table>
            </li>
        </volist>
            <li class="pull-left">{$page}</li>
        </ul>
    </div>

</div>
</div>

<div class="hide" id="dialog-import" title="{:L('IMPORT_DATE')}">loading...</div>
<div class="hide" id="dialog-role-info" title="{:L('EMPLOYEE_INFORMATION')}">loading...</div>
<div class="hide" id="dialog-fenpei" title="{:L('DISTRIBUTION_OF_CUSTOMERS')}">loading...</div>
<div class="hide" id="dialog-assign" title="{:L('DISTRIBUTION_OF_CUSTOMERS')}">loading...</div>
<div class="hide" id="dialog-share" title="客户共享">loading...</div>
<script type="text/javascript">

var url = "{:U('customer/getcurrentstatus')}";
var limit_size = 1000;
var count = '{$count}';
var i = 1;
function remainTime(){
    var id_array = new Array();
    $("input[class='check_list']:checked").each(function() {
        id_array.push($(this).val());
    });
    $.get(url,function(data){
        if(data.data == 0){
            if((i-1)*limit_size < count){
                $("#act").val('excel');
                $("#daochu").val(id_array);
                $("#current_page").val(i);
                $("#export_limit").val(limit_size);
                $("#searchForm").submit();
                setTimeout("remainTime()",1000);
                i++;
            }else{
                $("#act").val('');
                i = 1;
            }
        }else{
            setTimeout("remainTime()",1000);
        }
    }, 'json');
}
<if condition="C('ismobile') eq 1">width=$('.container').width() * 0.9;<else/>width=600;</if>
$("#dialog-share").dialog({
    autoOpen: false,
    modal: true,
    width: 530,
    maxHeight: 600,
    position: ["center",100]
});
$("#dialog-role-info").dialog({
    autoOpen: false,
    modal: true,
    width: width,
    maxHeight: 400,
    position: ["center",100]
});
$("#dialog-import").dialog({
    autoOpen: false,
    modal: true,
    width: width,
    maxHeight: 400,
    position: ["center",100]
});
$("#dialog-fenpei").dialog({
    autoOpen: false,
    modal: true,
    width: width,
    maxHeight: 400,
    position: ["center",100],
    buttons: {
        "Ok": function () {
            $('#fenpei_form').submit();
            $(this).dialog("close");
        },
        "Cancel": function () {
            $(this).dialog("close");
        }
    }
});
$("#dialog-assign").dialog({
    autoOpen: false,
    modal: true,
    width: width,
    maxHeight: 400,
    position: ["center",100],
    buttons: {
        "Ok": function () {
            var owner_role_id = $('input[name="owner_role_id"]').val();
            var message_alert = $('input:checkbox[name="message_alert"]:checked').val();
            var sms_alert = $('input:checkbox[name="sms_alert"]:checked').val();
            var email_alert = $('input:checkbox[name="email_alert"]:checked').val();

            $("#hidden_owner_id").val(owner_role_id);
            $("#hidden_message").val(message_alert);
            $("#hidden_sms").val(sms_alert);
            $("#hidden_email").val(email_alert);

            $("#form1").attr('action', '{:U("customer/receive")}');
            $('#operating_type').val('assign');
            $("#form1").submit();
            $(this).dialog("close");
        },
        "Cancel": function () {
            $(this).dialog("close");
        }
    }
});
function changeContent(){
    a = $("#select1  option:selected").val();
    window.location.href="{:U('customer/index', 'by=')}"+a;
}
<if condition="$customerlist neq null">
$nodes_num = document.getElementById("childNodes_num").children.length;
$("#td_colspan").attr('colspan',$nodes_num);
</if>
$(function(){

    //审核试吃
    $("input[name='pass']").click(function(){
        var tasteId = $(this).parents("li").attr("taste-id");
        if (window.confirm("确定审核通过吗?")) {
            $.get("{:U('taste/checkTaste')}", {'taste_id':tasteId, 'r':Math.random()}, function(data){
                if (data.code == 0) {
                    alert("审核通过");
                }
            }, 'json');
        }
        return false;
    });

    //审核试吃不通过
    $("input[name='unpass']").click(function(){
        var tasteId = $(this).parents("li").attr("taste-id");
        if (window.confirm("确定审核不通过吗?")) {
            $.get("{:U('taste/checkTaste')}", {'taste_id':tasteId, 'ac':'unpass', 'r':Math.random()}, function(data){
                if (data.code == 0) {
                    alert("审核不通过");
                    window.location.reload(true);
                }
            }, 'json');
        }
        return false;
    });


    $("#excelExport").click(function(){
        if(count > limit_size){
            if(confirm('当前导出量过大，将分几次导出，可能需要您等待一段时间，是否继续?')){
                remainTime();
            }
        }else{
            if(confirm("{:L('CONFIRM_EXPORT_CUSTOMER')}")){
                remainTime();
            }
        }
        /* if(confirm("{:L('CONFIRM_EXPORT_CUSTOMER')}")){
         $("#act").val('excel');
         $("#searchForm").submit();
         } */
    });


    $("#check_all").click(function(){
        $("input[class='check_list']").prop('checked', $(this).prop("checked"));
    });
    $('#delete').click(function(){
        if(confirm('{:L('Confirm_to_delete')}')){
        <if condition="$Think.session.admin eq 1 and $Think.get.by eq 'deleted'">
            $("#form1").attr('action', '{:U("customer/completedelete","content=".$_GET['content'])}');
            $("#form1").submit();
        <else />
            $("#form1").attr('action', '{:U("customer/delete","content=".$_GET['content'])}');
            $("#form1").submit();
        </if>
        }
    });
    $('#remove').click(function(){
        if(confirm('{:L('CONFIRMED_IN_THE_CUSTOMER_POOL')}')){
            $("#form1").attr('action', '{:U("customer/remove")}');
            $('#operating_type').attr('value', 'remove');
            $("#form1").submit();
        }
    });
    $("#import_excel").click(function(){
        $('#dialog-import').dialog('open');
        $('#dialog-import').load('{:U("customer/excelimport")}');
    });
    $(".role_info").click(function(){
        $role_id = $(this).attr('rel');
        $('#dialog-role-info').dialog('open');
        $('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
    });
    $("#check_send").click(function(){
        var id_array = new Array();
        $("input[class='check_list']:checked").each(function(){
            id_array.push($(this).val());
        });
        if(id_array.length == 0){
            alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
        }else{
            var customer_ids = id_array.join(",");
            window.open("{:U('setting/sendSms', 'model=customer&customer_ids=')}"+customer_ids);
        }
    });
    $("#check_send_email").click(function(){
        var id_array = new Array();
        $("input[class='check_list']:checked").each(function(){
            id_array.push($(this).val());
        });

        if(id_array.length == 0){
            alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
        }else{
            var customer_ids = id_array.join(",");
            window.open("{:U('setting/sendemail', 'model=customer&customer_ids=')}"+customer_ids);
        }
    });

    $("#page_send").click(function(){
        var id_array = new Array();
        $("input[class='check_list']").each(function(){
            id_array.push($(this).val());
        });
        if(id_array.length == 0){
            alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
        }else{
            var customer_ids = id_array.join(",");
            window.open("{:U('setting/sendSms', 'model=customer&customer_ids=')}"+customer_ids);
        }
    });
    $("#page_send_email").click(function(){
        var id_array = new Array();
        $("input[class='check_list']").each(function(){
            id_array.push($(this).val());
        });
        if(id_array.length == 0){
            alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
        }else{
            var customer_ids = id_array.join(",");
            window.open("{:U('setting/sendemail', 'model=customer&customer_ids=')}"+customer_ids);
        }
    });
    $("#all_send_email").click(function(){
        window.open("{:U('setting/sendemail', 'model=customer&customer_ids=all')}");
    });

    $("#all_send").click(function(){
        $("#act").val('sms');
        $("#searchForm").submit();
    });

    $(".fenpei").click(function(){
        $customer_id = $(this).attr('rel');
        $('#dialog-fenpei').dialog('open');
        $('#dialog-fenpei').load('{:U("customer/fenpei","customer_id=")}'+$customer_id);
    });
    $('#batch_assign').click(function(){
        $('#dialog-assign').dialog('open');
        $('#dialog-assign').load('{:U("customer/fenpei")}');
    });
    $('#batch_receive').click(function(){
        if(confirm('{:L('SURE_YOU_WANT_TO_BATCH_TO_RECEIVE')}')){
            $("#form1").attr('action', '{:U("customer/receive")}');
            $('#operating_type').attr('value', 'receive');
            $("#form1").submit();
        }
    });
    $("#dosearch").click(function(){
        result = checkSearchForm();
        if(result){
            $("#act").val('search');
            $("#searchForm").submit();
        }
    });

    $("#share").click(function(){
        var id_array = new Array();
        $("input[class='check_list']:checked").each(function(){
            id_array.push($(this).val());
        });
        if(id_array.length == 0){
            alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CUSTOMERS')}');
        }else{
            var customer_ids = id_array.join(",");
            $('#dialog-share').dialog('open');
            $('#dialog-share').load("{:U("customer/share")}","customer_id="+customer_ids);
        }
    });

    $("#close_share").click(function(){
        if(confirm('确定批量取消分享？')){
            $("#form1").attr('action', '{:U("customer/close_share")}');
            $("#form1").submit();
        }
    });

    $('#all_focus').click(function(){
        if(confirm('确定批量添加关注？')){
            $("#form1").attr('action', '{:U("customer/batchfocus")}');
            $("#form1").submit();
        }
    });
    $('#close_focus').click(function(){
        if(confirm('确定批量取消关注？')){
            $("#form1").attr('action', '{:U("customer/batchclose")}');
            $("#form1").submit();
        }
    });


    <if condition="$Think.get.field neq null">
    $("#field option[value='{$Think.get.field}']").prop("selected", true);changeCondition();
    $("#condition option[value='{$Think.get.condition}']").prop("selected", true);changeSearch();
    $("#search").val('{$Think.get.search}');
    <if condition="$_GET['state']">
    new PCAS("state","city","area","{$Think.get.state}","{$Think.get.city}","{$Think.get.area}");
    </if>
    <else />
    $("#field option[value='status_id']").prop("selected", true);changeCondition();
    </if>
});

</script>
<include file="Public:footer" />